﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace QFlow.Data
{
    public static class ItemTypeExtension
    {
        private static ItemType _Pending, _Received, _Returned;

        public static ItemType GetPendingType(this Table<ItemType> queriable)
        {
            return queriable.Single(it => it.ItemTypeID == 1);
        }

        public static ItemType GetReceivedType(this Table<ItemType> queriable)
        {
            return queriable.Single(it => it.ItemTypeID == 2);
        }

        public static ItemType GetReturnedType(this Table<ItemType> queriable)
        {
            return queriable.Single(it => it.ItemTypeID == 3);
        }

        public static bool IsPending(this Table<ItemType> queriable, int itemTypeId)
        {
            if (_Pending == null)
                _Pending = GetPendingType(queriable);
            return itemTypeId == _Pending.ItemTypeID;
        }

        public static bool IsReceived(this Table<ItemType> queriable, int itemTypeId)
        {
            if (_Received == null)
                _Received = GetReceivedType(queriable);
            return itemTypeId == _Received.ItemTypeID;
        }

        public static bool IsReturned(this Table<ItemType> queriable, int itemTypeId)
        {
            if (_Returned == null)
                _Returned = GetReturnedType(queriable);
            return itemTypeId == _Returned.ItemTypeID;
        }
    }
}
